#include <stdio.h>

/*
 * 对过程的间接调用
 */

int func(int a, int b)
{
	return a + b;
}

int main()
{
	int (*zzz)(int a, int b) = func;

	printf("0x%x\n", zzz(0x666, 0x777));	// 0xddd

	return 0;
}

#if 0

/*
 * intel
 */
0000000000001149 <func>:
    1149:	f3 0f 1e fa          	endbr64 
    114d:	55                   	push   %rbp
    114e:	48 89 e5             	mov    %rsp,%rbp
    1151:	89 7d fc             	mov    %edi,-0x4(%rbp)	// (rbp-0x4)=edi
    1154:	89 75 f8             	mov    %esi,-0x8(%rbp)	// (rbp-0x8)=esi
    1157:	8b 55 fc             	mov    -0x4(%rbp),%edx	// edx=(rbp-0x4)
    115a:	8b 45 f8             	mov    -0x8(%rbp),%eax	// eax=(rbp-0x8)
    115d:	01 d0                	add    %edx,%eax	// eax+=edx
    115f:	5d                   	pop    %rbp
    1160:	c3                   	retq   

0000000000001161 <main>:
    1161:	f3 0f 1e fa          	endbr64 
    1165:	55                   	push   %rbp
    1166:	48 89 e5             	mov    %rsp,%rbp
    1169:	48 83 ec 10          	sub    $0x10,%rsp	// rsp-=0x10
    116d:	48 8d 05 d5 ff ff ff 	lea    -0x2b(%rip),%rax        # 1149 <func> 	// rax=rip-0x2b
    1174:	48 89 45 f8          	mov    %rax,-0x8(%rbp)	// (rbp-0x8)=rax
    1178:	48 8b 45 f8          	mov    -0x8(%rbp),%rax	// rax=(rbp-0x8)
    117c:	be 77 07 00 00       	mov    $0x777,%esi	// esi=0x777
    1181:	bf 66 06 00 00       	mov    $0x666,%edi	// edi=0x666
    1186:	ff d0                	callq  *%rax		// func(edi, esi)
    1188:	89 c6                	mov    %eax,%esi	// esi=eax
    118a:	48 8d 3d 73 0e 00 00 	lea    0xe73(%rip),%rdi        # 2004 <_IO_stdin_used+0x4>	// rdi=rip+0xe73
    1191:	b8 00 00 00 00       	mov    $0x0,%eax	// eax=0
    1196:	e8 b5 fe ff ff       	callq  1050 <printf@plt>	// printf(rdi, esi)
    119b:	b8 00 00 00 00       	mov    $0x0,%eax	// eax=0
    11a0:	c9                   	leaveq 
    11a1:	c3                   	retq   
    11a2:	66 2e 0f 1f 84 00 00 	nopw   %cs:0x0(%rax,%rax,1)
    11a9:	00 00 00 
    11ac:	0f 1f 40 00          	nopl   0x0(%rax)

/*
 * arm
 */
000000000040055c <func>:
  40055c:	d10043ff 	sub	sp, sp, #0x10
  400560:	b9000fe0 	str	w0, [sp, #12]	// [sp+12]=w0
  400564:	b9000be1 	str	w1, [sp, #8]	// [sp+8]=w1
  400568:	b9400fe1 	ldr	w1, [sp, #12]	// w1=[sp+12]
  40056c:	b9400be0 	ldr	w0, [sp, #8]	// w0=[sp+8]
  400570:	0b000020 	add	w0, w1, w0	// w0=w1+w0
  400574:	910043ff 	add	sp, sp, #0x10	
  400578:	d65f03c0 	ret

000000000040057c <main>:
  40057c:	a9be7bfd 	stp	x29, x30, [sp, #-32]!
  400580:	910003fd 	mov	x29, sp
  400584:	90000000 	adrp	x0, 400000 <_init-0x3e8>
  400588:	91157000 	add	x0, x0, #0x55c	// x0=40055c=func
  40058c:	f9000fa0 	str	x0, [x29, #24]	// [x29+24]=x0
  400590:	f9400fa2 	ldr	x2, [x29, #24]	// x2=[x29+24]
  400594:	5280eee1 	mov	w1, #0x777                 	// #1911
  400598:	5280ccc0 	mov	w0, #0x666                 	// #1638
  40059c:	d63f0040 	blr	x2		// func(w0, w1)
  4005a0:	2a0003e1 	mov	w1, w0
  4005a4:	90000000 	adrp	x0, 400000 <_init-0x3e8>
  4005a8:	9119c000 	add	x0, x0, #0x670
  4005ac:	97ffffa9 	bl	400450 <printf@plt>
  4005b0:	52800000 	mov	w0, #0x0                   	// #0
  4005b4:	a8c27bfd 	ldp	x29, x30, [sp], #32
  4005b8:	d65f03c0 	ret
  4005bc:	00000000 	.inst	0x00000000 ; undefined

#endif
